package com.ruoyi.web.controller.carte;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.request.*;
import com.ruoyi.system.service.carte.trans.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * carte服务器Controller
 * 
 * @author ruoyi
 * @date 2024-02-28
 */
@Api( tags = {"Trans相关接口"})
@Controller
@RequestMapping("/system/trans")
public class XxkTransController extends BaseController
{
    @Autowired
    private ITransExecute transexecuteImpl;

    @Autowired
    private ITransStatus transStatusImpl;

    @Autowired
    private ITransStop transStopImpl;

    @Autowired
    private ITransStart transStartImpl;

    @Autowired
    private ITransPause transPauseImpl;

    @Autowired
    private ITransStartExec transStartExecImpl;

    @Autowired
    private ITransRun transRunImpl;

    @Autowired
    private ITransRemove transRemoveImpl;

    @Autowired
    private ITransImage transImageImpl;

    @Autowired
    private ITransSniffStep transSniffStepImpl;


    @ApiOperation(value = "执行转换")
    @PostMapping("/executeTrans")
    @ResponseBody
    public AjaxResult executeTrans(@RequestBody TransExecuteRequest transRequest) throws Exception
    {
        String result = transexecuteImpl.executeTrans(transRequest);
        if(StringUtils.isBlank(result)){
            result="调用成功";
        }
        return success(result);
    }
    @ApiOperation(value = "获取转换状态")
    @PostMapping("/transStatus")
    @ResponseBody
    public String transStatus(@RequestBody TransStatusRequest transRequest)
    {
        String result = transStatusImpl.transStatus(transRequest);
        return result;
    }

    @ApiOperation(value = "停止转换")
    @PostMapping("/stopTrans")
    @ResponseBody
    public String stopTrans(@RequestBody TransStopRequest transRequest)
    {
        String result = transStopImpl.stopTrans(transRequest);
        return result;
    }

    @ApiOperation(value = "启动转换")
    @PostMapping("/startTrans")
    @ResponseBody
    public String startTrans(@RequestBody TransStartRequest transRequest)
    {
        String result = transStartImpl.startTrans(transRequest);
        return result;
    }


    @ApiOperation(value = "暂停转换")
    @PostMapping("/pauseTrans")
    @ResponseBody
    public String pauseTrans(@RequestBody TransPauseRequest transRequest)
    {
        String result = transPauseImpl.pauseTrans(transRequest);
        return result;
    }

    @ApiOperation(value = "启动执行转换，可以用于启动执行作业（Job）或转换")
    @PostMapping("/startExec")
    @ResponseBody
    public String startExec(@RequestBody TransStartExecRequest transRequest)
    {
        String result = transStartExecImpl.startExecTrans(transRequest);
        return result;
    }

    @ApiOperation(value = "从企业存储库执行转换")
    @PostMapping("/runTrans")
    @ResponseBody
    public String runTrans(@RequestBody TransRunRequest transRequest)
    {
        String result = transRunImpl.runTrans(transRequest);
        return result;
    }

    @ApiOperation(value = "删除转换")
    @PostMapping("/removeTrans")
    @ResponseBody
    public String removeTrans(@RequestBody TransRemoveRequest transRequest)
    {
        String result = transRemoveImpl.removeTrans(transRequest);
        return result;
    }

    @ApiOperation(value = "从指定转换的指定步骤中嗅探元数据和数据。")
    @PostMapping("/sniffStep")
    @ResponseBody
    public String sniffStep(@RequestBody TransSniffStepRequest transRequest)
    {
        String result = transSniffStepImpl.sniffStepTrans(transRequest);
        return result;
    }

    @ApiOperation(value = "获取转换图片")
    @PostMapping("/transImage")
    @ResponseBody
    public void transImage(@RequestBody TransImageRequest transRequest, HttpServletResponse response)
    {
        transImageImpl.transImage(transRequest,response);
    }

}
